#!/bin/bash

SUDO="sudo "
if [[ $(id -u) -eq 0 ]]; then SUDO=""; fi

read -p "Enter project (default python, e.g. | java | rust | go | vcpkg .etc): " project </dev/tty
project=$(echo "$project" | tr -s '[:space:]')
if [[ "$project" == "" ]]; then project="python"; fi

read -p "Enter project name: " project_name </dev/tty
project_name=$(echo "$project_name" | tr -s '[:space:]')
if [[ "$project_name" == "" ]]; then echo "you must enter your project name."; exit -1; fi

read -p "Enter project parts (default all, e.g. vscode | all ): " project_part </dev/tty
project_part=$(echo "$project_part" | tr -s '[:space:]')
if [[ "$project_part" == "" ]]; then project_part="all"; fi


mkdir -p $project_name
cd $project_name

$SUDO rm -rf /tmp/project-demo
git clone https://gitee.com/wyanlord/project-demo.git /tmp/project-demo

if [[ "$project_part" == "all" ]]; then
    cp -r /tmp/project-demo/$project/* ./
fi

cp -a /tmp/project-demo/$project/.vscode ./

case $project in
    python)
        echo -e "\n\tpython3 -m venv .venv"
        echo -e "\t.venv/bin/python3 -m pip install poetry"
        echo -e "\t.venv/bin/python3 -m poetry add numpy"
        echo -e "\t.venv/bin/python3 -m poetry build"
        ;;
    java)
        echo "java"
        ;;
    rust)
        echo "rust"
        ;;
    go)
        echo "go"
        ;;
    vcpkg)
        echo "vcpkg"
        ;;
    *)
        echo "unsupport project"
        exit -1
esac
